from infirmary_admin_src.infirmary_common.infirmary_controller import IBaseController
from infirmary_admin_src.infirmary_common.infirmary_controller.rest_controller_with_depends import \
    RestControllerWithDepends
from fastapi import Request, Depends, Path, Body

from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.infirmary.businesses.schemas import SchemaBase
from infirmary_admin_src.infirmary_smart_admin.infirmary_biz.system.employee.services import EmployeeBusinesses
from infirmary_admin_src.infirmary_smart_admin.infirmary_utils.convert2_help import convert_dict_to_camel_case



class XParam(SchemaBase):
    '''
    账号密码登录参数
    '''
    department_id: int = Body(None, alias='departmentId', title="department_id", description='权限类型')
    disabled_flag: bool = Body(False, alias='disabledFlag', title="deleted_flag", description='是否禁用标记')
    keyword: str = Body(None, alias='keyword', title="keyword", description='keyword')
    pageNum: int = Body(default=1, alias='pageNum', title="pageNum", description='权限类型')
    pageSize: int = Body(default=10, alias='pageSize', title="pageSize", description='权限类型')


class IController(IBaseController):
    '''
    定制相关约束检测函数逻辑步序
    '''

    def __init__(self, *, request: Request,
                 schema_param: XParam,
                 ):
        super().__init__(request=request)
        # 入参参数
        # 入参参数
        self.schema_param = schema_param


@RestControllerWithDepends()
class SystemEmployeeQueryController(IController):

    def business_login(self):
        pass
        # 查询用户信息，联表查询比较麻烦
        _result_nums_total, lists = EmployeeBusinesses.get_sys_employee_List_by_admin_role_infos(
            keyword=self.schema_param.keyword,
            department_id=self.schema_param.department_id,
            disabled_flag=self.schema_param.disabled_flag,
            pageNum=self.schema_param.pageNum,
            pageSize=self.schema_param.pageSize,
        )
        # 查询所有角色信息，进行匹配管理显示
        listdata =None
        if lists:
            listdata = [convert_dict_to_camel_case(v, keepkey=['departmentId', 'employeeId', 'gender', 'sort'], delkeys=['loginPwd'])for v in lists]
        return {
            'emptyFlag': False if _result_nums_total > 0 else True,
            'list':listdata if listdata else [],
            'pageNum': self.schema_param.pageNum,
            'pageSize': self.schema_param.pageSize,
            'pages': 2,
            'total': _result_nums_total
        }
